package controllers.monitor;

import helpers.ClientRequest;

import java.util.Date;
import java.util.List;

import action.BeforeAfterAction;

import com.fasterxml.jackson.databind.node.ObjectNode;

import models.monitor.ScheduleETL;
import play.*;
import play.mvc.*;
import play.libs.Json;
import service.Paging;
import service.Utils;

@With(BeforeAfterAction.class)
public class ScheduleController extends Controller {

    public static Result index() {
        return ok(views.html.monitor.schedule.index.render("Your new application is ready TEST."));
    }
    
    @BodyParser.Of(BodyParser.Json.class)
    public static Result search() {
    	
    	// Get query string
    	int type = Integer.parseInt(request().getQueryString("type"));
    	int status = Integer.parseInt(request().getQueryString("status"));
    	
    	Date startTime = Utils.stringToDate(request().getQueryString("startTime"));
    	Date endTime = Utils.stringToDate(request().getQueryString("endTime"));
    	
        Paging paging = ScheduleETL.search(ClientRequest.getCurrent().appId, type, status, startTime, endTime);
         
    	ObjectNode dataJson = Json.newObject();
    	dataJson.put("total", paging.totalRow);
    	dataJson.put("list", Json.toJson(paging.dataList));
    	
        return ok(dataJson);
    }
    
}
